/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.recharge.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.recharge.entity.SiteUserRecharge;
import com.thinkgem.jeesite.modules.recharge.service.SiteUserRechargeService;

/**
 * 用户充值记录Controller
 * @author gy
 * @version 2017-08-05
 */
@Controller
@RequestMapping(value = "${adminPath}/recharge/siteUserRecharge")
public class SiteUserRechargeController extends BaseController {

	@Autowired
	private SiteUserRechargeService siteUserRechargeService;
	
	@ModelAttribute
	public SiteUserRecharge get(@RequestParam(required=false) String id) {
		SiteUserRecharge entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = siteUserRechargeService.get(id);
		}
		if (entity == null){
			entity = new SiteUserRecharge();
		}
		return entity;
	}
	
	@RequiresPermissions("recharge:siteUserRecharge:view")
	@RequestMapping(value = {"list", ""})
	public String list(SiteUserRecharge siteUserRecharge, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<SiteUserRecharge> page = siteUserRechargeService.findPage(new Page<SiteUserRecharge>(request, response), siteUserRecharge); 
		model.addAttribute("page", page);
		return "modules/recharge/siteUserRechargeList";
	}

	@RequiresPermissions("recharge:siteUserRecharge:view")
	@RequestMapping(value = "form")
	public String form(SiteUserRecharge siteUserRecharge, Model model) {
		model.addAttribute("siteUserRecharge", siteUserRecharge);
		return "modules/recharge/siteUserRechargeForm";
	}

	@RequiresPermissions("recharge:siteUserRecharge:edit")
	@RequestMapping(value = "save")
	public String save(SiteUserRecharge siteUserRecharge, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, siteUserRecharge)){
			return form(siteUserRecharge, model);
		}
		siteUserRechargeService.save(siteUserRecharge);
		addMessage(redirectAttributes, "保存查询成功过成功");
		return "redirect:"+Global.getAdminPath()+"/recharge/siteUserRecharge/?repage";
	}
	
	@RequiresPermissions("recharge:siteUserRecharge:edit")
	@RequestMapping(value = "delete")
	public String delete(SiteUserRecharge siteUserRecharge, RedirectAttributes redirectAttributes) {
		siteUserRechargeService.delete(siteUserRecharge);
		addMessage(redirectAttributes, "删除查询成功过成功");
		return "redirect:"+Global.getAdminPath()+"/recharge/siteUserRecharge/?repage";
	}

}